package com.sirius.meta.mall.bus.jdk8.stream;

import com.sirius.meta.mall.bus.jdk8.swagger.model.User;

import java.util.ArrayList;
import java.util.IntSummaryStatistics;
import java.util.Map;
import java.util.function.BiConsumer;
import java.util.function.Function;
import java.util.stream.Collectors;
import java.util.stream.Stream;

/**
 * @author Surging
 * @version 1.0
 * @ClassName StreamTest
 * @date 2022/1/24 15:53
 * @desc
 */
public class StreamTest {

    public static void main(String[] args) {
        ArrayList<User> users = new ArrayList<>();
        users.add(new User("fxd", 18));
        users.add(new User("cp", 19));
        users.add(new User("xfn", 20));
        users.add(new User("zzq", 19));
        //创建Stream流
        Stream<User> stream = users.stream();
        Map<String, User> collect = stream.collect(Collectors.toMap(user -> user.getUserName(), user -> user));
        collect.forEach((BiConsumer<? super String, ? super User>) (o, o2) ->System.out.println(o+ "," + o2));
        IntSummaryStatistics stats = users.stream().mapToInt((user) -> user.getAge()).summaryStatistics();
        System.out.println("" + stats.getSum());
    }
}
